<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Jenkins 简单使用 | 海内存知已，天涯若比邻</title><meta name="keywords" content="jenkins"><meta name="author" content="mowei"><meta name="copyright" content="mowei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1.GitLab安装使用1.在ssh下安装官方安装文档：https:&#x2F;&#x2F;gitlab.cn&#x2F;install&#x2F;?version&#x3D;ce 1 安装依赖123sudo yum install -y curl policycoreutils-python openssh-server perlsudo systemctl enable sshdsudo systemctl start sshd 2 配置镜像">
<meta property="og:type" content="article">
<meta property="og:title" content="Jenkins 简单使用">
<meta property="og:url" content="https://gitee.com/momomomowei/blog/jenkins/Jenkins/index.html">
<meta property="og:site_name" content="海内存知已，天涯若比邻">
<meta property="og:description" content="1.GitLab安装使用1.在ssh下安装官方安装文档：https:&#x2F;&#x2F;gitlab.cn&#x2F;install&#x2F;?version&#x3D;ce 1 安装依赖123sudo yum install -y curl policycoreutils-python openssh-server perlsudo systemctl enable sshdsudo systemctl start sshd 2 配置镜像">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/momomomowei/images/jenkins_cover.jpeg">
<meta property="article:published_time" content="2023-03-18T06:06:43.000Z">
<meta property="article:modified_time" content="2024-04-21T07:24:14.389Z">
<meta property="article:author" content="mowei">
<meta property="article:tag" content="jenkins">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/momomomowei/images/jenkins_cover.jpeg"><link rel="shortcut icon" href="/media/favicon.png"><link rel="canonical" href="https://gitee.com/momomomowei/blog/jenkins/Jenkins/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Jenkins 简单使用',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-04-21 15:24:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    document.addEventListener('pjax:complete', detectApple)})(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/media/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">29</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/jenkins_cover.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">海内存知已，天涯若比邻</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Jenkins 简单使用</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-18T06:06:43.000Z" title="发表于 2023-03-18 14:06:43">2023-03-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-21T07:24:14.389Z" title="更新于 2024-04-21 15:24:14">2024-04-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/jenkins/">jenkins</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>19分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Jenkins 简单使用"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="1-GitLab安装使用"><a href="#1-GitLab安装使用" class="headerlink" title="1.GitLab安装使用"></a>1.GitLab安装使用</h2><h3 id="1-在ssh下安装"><a href="#1-在ssh下安装" class="headerlink" title="1.在ssh下安装"></a>1.在ssh下安装</h3><p>官方安装文档：<a target="_blank" rel="noopener" href="https://gitlab.cn/install/?version=ce">https://gitlab.cn/install/?version=ce</a></p>
<h4 id="1-安装依赖"><a href="#1-安装依赖" class="headerlink" title="1 安装依赖"></a>1 安装依赖</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo yum install -y curl policycoreutils-python openssh-server perl</span><br><span class="line">sudo systemctl enable sshd</span><br><span class="line">sudo systemctl start sshd</span><br></pre></td></tr></table></figure>
<h4 id="2-配置镜像"><a href="#2-配置镜像" class="headerlink" title="2 配置镜像"></a>2 配置镜像</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash</span><br></pre></td></tr></table></figure>
<h4 id="3-开始安装"><a href="#3-开始安装" class="headerlink" title="3 开始安装"></a>3 开始安装</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo EXTERNAL_URL=&quot;http://192.168.44.103&quot; yum install -y gitlab-jh</span><br></pre></td></tr></table></figure>
<p>除非您在安装过程中指定了自定义密码，否则将随机生成一个密码并存储在 <code>/etc/gitlab/initial_root_password</code> 文件中(出于安全原因，24 小时后，此文件会被第一次 <code>gitlab-ctl reconfigure</code> 自动删除，因此若使用随机密码登录，建议安装成功初始登录成功之后，立即修改初始密码）。使用此密码和用户名 <code>root</code> 登录。</p>
<h4 id="4-gitlab常用命令"><a href="#4-gitlab常用命令" class="headerlink" title="4 gitlab常用命令"></a>4 gitlab常用命令</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">gitlab-ctl start                  # 启动所有 gitlab 组件；</span><br><span class="line">gitlab-ctl stop                   # 停止所有 gitlab 组件；</span><br><span class="line">gitlab-ctl restart                # 重启所有 gitlab 组件；</span><br><span class="line">gitlab-ctl status                 # 查看服务状态；</span><br><span class="line">gitlab-ctl reconfigure            # 启动服务；</span><br><span class="line">vi /etc/gitlab/gitlab.rb         # 修改默认的配置文件；</span><br><span class="line">gitlab-ctl tail                   # 查看日志；</span><br></pre></td></tr></table></figure>
<h4 id="5-自启设置"><a href="#5-自启设置" class="headerlink" title="5 自启设置"></a>5 自启设置</h4><p>禁止 Gitlab 开机自启动：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl disable gitlab-runsvdir.service</span><br></pre></td></tr></table></figure>
<p>启用 Gitlab 开机自启动：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable gitlab-runsvdir.service</span><br></pre></td></tr></table></figure>
<h3 id="2-在docker下安装"><a href="#2-在docker下安装" class="headerlink" title="2.在docker下安装"></a>2.在docker下安装</h3><blockquote>
<p>参考链接：<a target="_blank" rel="noopener" href="https://juejin.cn/post/6901810354897027080">https://juejin.cn/post/6901810354897027080</a></p>
</blockquote>
<h4 id="1-拉取镜像"><a href="#1-拉取镜像" class="headerlink" title="1 拉取镜像"></a>1 拉取镜像</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull registry.gitlab.cn/omnibus/gitlab-jh</span><br></pre></td></tr></table></figure>
<h4 id="2-添加环境变量"><a href="#2-添加环境变量" class="headerlink" title="2 添加环境变量"></a>2 添加环境变量</h4><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/profile</span><br><span class="line"></span><br><span class="line"><span class="comment">#添加环境变量，$HOME表示当前用户家目录</span></span><br><span class="line"><span class="built_in">export</span> GITLAB_HOME=<span class="variable">$HOME</span>/gitlab</span><br><span class="line"></span><br><span class="line"><span class="comment">#立即生效</span></span><br><span class="line"><span class="built_in">source</span> /etc/profile</span><br></pre></td></tr></table></figure>
<h4 id="2-添加容器"><a href="#2-添加容器" class="headerlink" title="2 添加容器"></a>2 添加容器</h4><blockquote>
<p>—shm-size：共享内存</p>
</blockquote>
<p><code>GitLab</code>容器使用主机安装的卷来存储持久数据：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>挂载到宿主机指定目录</th>
<th>容器目录</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>$GITLAB_HOME/data</td>
<td>/var/opt/gitlab</td>
<td>用于存储应用程序数据。</td>
</tr>
<tr>
<td>$GITLAB_HOME/logs</td>
<td>/var/log/gitlab</td>
<td>用于存储日志。</td>
</tr>
<tr>
<td>$GITLAB_HOME/config</td>
<td>/etc/gitlab</td>
<td>用于存储GitLab配置文件。</td>
</tr>
</tbody>
</table>
</div>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">docker run --detach \</span><br><span class="line">  --publish 443:443 \</span><br><span class="line">  --publish 8888:80 \</span><br><span class="line">  --name gitlab \</span><br><span class="line">  --restart always \</span><br><span class="line">  --volume $GITLAB_HOME/config:/etc/gitlab:Z \</span><br><span class="line">  --volume $GITLAB_HOME/logs:/var/log/gitlab:Z \</span><br><span class="line">  --volume $GITLAB_HOME/data:/var/opt/gitlab:Z \</span><br><span class="line">  --shm-size 256m \</span><br><span class="line">  registry.gitlab.cn/omnibus/gitlab-jh:latest</span><br></pre></td></tr></table></figure>
<h4 id="2-启动容器"><a href="#2-启动容器" class="headerlink" title="2.启动容器"></a>2.启动容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start gitlab</span><br></pre></td></tr></table></figure>
<h4 id="3-查看已存在的容器"><a href="#3-查看已存在的容器" class="headerlink" title="3.查看已存在的容器"></a>3.查看已存在的容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps -a</span><br></pre></td></tr></table></figure>
<h4 id="4-进入容器"><a href="#4-进入容器" class="headerlink" title="4.进入容器"></a>4.进入容器</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it  gitlab /bin/bash</span><br></pre></td></tr></table></figure>
<h4 id="3-访问"><a href="#3-访问" class="headerlink" title="3.访问"></a>3.访问</h4><p><a target="_blank" rel="noopener" href="http://192.168.44.101">http://192.168.44.101</a></p>
<p>当首次运行出现502错误的时候排查两个原因</p>
<ol>
<li>虚拟机内存至少需要4g</li>
<li>稍微再等等刷新一下可能就好了</li>
</ol>
<h4 id="4-管理员账号登录"><a href="#4-管理员账号登录" class="headerlink" title="4.管理员账号登录"></a>4.管理员账号登录</h4><p>用户名：root</p>
<p>密码存在下面文件中，登录后需要改密码不然24小时之后会失效</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#cat /etc/gitlab/initial_root_password</span></span><br><span class="line"><span class="built_in">echo</span> \<span class="variable">$HOME</span>/gitlab/config/initial_root_password</span><br></pre></td></tr></table></figure>
<h4 id="5-其他配置"><a href="#5-其他配置" class="headerlink" title="5.其他配置"></a>5.其他配置</h4><blockquote>
<p>按上面的方式，<code>gitlab</code>容器<code>运行</code>没问题，但在gitlab上创建项目的时候，生成项目的URL访问地址是按容器的hostname来生成的，也就是容器的id。作为gitlab服务器，我们需要一个固定的URL访问地址，于是需要配置<code>gitlab.rb</code> （宿主机路径：$HOME/gitlab/config/gitlab.rb), 配置http协议所使用的访问地址</p>
</blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通过vim 来编辑相应的配置, $HOME是当前系统的根目录,根据自己的路径自行修改</span></span><br><span class="line">vim <span class="variable">$HOME</span>/gitlab/config/gitlab.rb</span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置http协议所使用的访问地址,不加端口号默认为80</span></span><br><span class="line">external_url <span class="string">&#x27;http://127.0.0.1&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置ssh协议所使用的访问地址和端口</span></span><br><span class="line"><span class="comment">#gitlab_rails[&#x27;gitlab_ssh_host&#x27;] = &#x27;http://127.0.0.1&#x27;</span></span><br><span class="line"><span class="comment">#gitlab_rails[&#x27;gitlab_shell_ssh_port&#x27;] = 22 # 此端口是run时22端口映射的222端口</span></span><br></pre></td></tr></table></figure>
<h2 id="2-安装JDK"><a href="#2-安装JDK" class="headerlink" title="2.安装JDK"></a>2.安装JDK</h2><h3 id="1-检索可用包"><a href="#1-检索可用包" class="headerlink" title="1 检索可用包"></a>1 检索可用包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">yum search java|grep jdk</span><br><span class="line">yum install java-1.8.0-openjdk</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">默认yum安装java的时候会显示安装的是openjdk1.8 实则实际上只安装了jre</span></span><br><span class="line">yum install -y java-devel</span><br></pre></td></tr></table></figure>
<h3 id="2-配置JAVA-HOME"><a href="#2-配置JAVA-HOME" class="headerlink" title="2.配置JAVA_HOME"></a>2.配置JAVA_HOME</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/profile</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">在文件后面添加内容，javahome报错重新复制文件名再试！！</span></span><br><span class="line">export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el7_9.x86_64</span><br><span class="line">export JRE_HOME=$JAVA_HOME/jre</span><br><span class="line">export CLASSPATH=%JAVA_HOME%/lib:%JRE_HOME%/lib</span><br><span class="line">export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">立即生效</span></span><br><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>
<h2 id="3-Maven安装"><a href="#3-Maven安装" class="headerlink" title="3.Maven安装"></a>3.Maven安装</h2><blockquote>
<p>官网下载：<a target="_blank" rel="noopener" href="https://maven.apache.org/，下载后复制到Jenkins所在服务器解压缩重命名到/usr/local/maven">https://maven.apache.org/，下载后复制到Jenkins所在服务器解压缩重命名到/usr/local/maven</a></p>
</blockquote>
<h3 id="3-1-配置MAVEN-HOME"><a href="#3-1-配置MAVEN-HOME" class="headerlink" title="3.1 配置MAVEN_HOME"></a>3.1 配置MAVEN_HOME</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/profile</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">在文件后面添加内容</span></span><br><span class="line">export MAVEN_HOME=/usr/local/maven</span><br><span class="line">export PATH=$PATH:$MAVEN_HOME/bin</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">立即生效</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">jdk</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">/etc/alternatives/jre_openjdk</span></span><br><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>
<h3 id="3-2Maven阿里云镜像"><a href="#3-2Maven阿里云镜像" class="headerlink" title="3.2Maven阿里云镜像"></a>3.2Maven阿里云镜像</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">修改文件</span></span><br><span class="line">/usr/local/maven/conf/settings.xml</span><br></pre></td></tr></table></figure>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">settings</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://maven.apache.org/SETTINGS/1.0.0&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">localRepository</span>&gt;</span>/usr/local/maven/repository<span class="tag">&lt;/<span class="name">localRepository</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">pluginGroups</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">pluginGroup</span>&gt;</span>org.mortbay.jetty<span class="tag">&lt;/<span class="name">pluginGroup</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">pluginGroups</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">  <span class="tag">&lt;<span class="name">proxies</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">proxies</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">servers</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">server</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>releases<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">username</span>&gt;</span>ali<span class="tag">&lt;/<span class="name">username</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">password</span>&gt;</span>ali<span class="tag">&lt;/<span class="name">password</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">server</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">server</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>Snapshots<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">username</span>&gt;</span>ali<span class="tag">&lt;/<span class="name">username</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">password</span>&gt;</span>ali<span class="tag">&lt;/<span class="name">password</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">server</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">servers</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">mirrors</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>nexus<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>*<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span> </span><br><span class="line">      <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/groups/public/<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>nexus-public-snapshots<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>public-snapshots<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span> </span><br><span class="line">      <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/repositories/snapshots/<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>nexus-public-snapshots1<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>public-snapshots1<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span> </span><br><span class="line">      <span class="tag">&lt;<span class="name">url</span>&gt;</span>https://artifacts.alfresco.com/nexus/content/repositories/public/<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">mirrors</span>&gt;</span></span><br><span class="line"></span><br><span class="line">   <span class="tag">&lt;<span class="name">profiles</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>development<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">repositories</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">repository</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">id</span>&gt;</span>central<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://central<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">releases</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">releases</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">snapshots</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">snapshots</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">repository</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">repositories</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">pluginRepositories</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">pluginRepository</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">id</span>&gt;</span>central<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://central<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">releases</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">releases</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">snapshots</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">snapshots</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">pluginRepository</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">pluginRepositories</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>public-snapshots<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">repositories</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">repository</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">id</span>&gt;</span>public-snapshots<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://public-snapshots<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">releases</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>false<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;/<span class="name">releases</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">snapshots</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">snapshots</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">repository</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">repositories</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">pluginRepositories</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">pluginRepository</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">id</span>&gt;</span>public-snapshots<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://public-snapshots<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">releases</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>false<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;/<span class="name">releases</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">snapshots</span>&gt;</span><span class="tag">&lt;<span class="name">enabled</span>&gt;</span>true<span class="tag">&lt;/<span class="name">enabled</span>&gt;</span><span class="tag">&lt;<span class="name">updatePolicy</span>&gt;</span>always<span class="tag">&lt;/<span class="name">updatePolicy</span>&gt;</span><span class="tag">&lt;/<span class="name">snapshots</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">pluginRepository</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">pluginRepositories</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">profiles</span>&gt;</span></span><br><span class="line"> </span><br><span class="line">   <span class="tag">&lt;<span class="name">activeProfiles</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">activeProfile</span>&gt;</span>development<span class="tag">&lt;/<span class="name">activeProfile</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">activeProfile</span>&gt;</span>public-snapshots<span class="tag">&lt;/<span class="name">activeProfile</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">activeProfiles</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">settings</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="4-安装Jenkins"><a href="#4-安装Jenkins" class="headerlink" title="4.安装Jenkins"></a>4.安装Jenkins</h2><blockquote>
<p>参考链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/wzxyy_xianer/article/details/126423676">https://blog.csdn.net/wzxyy_xianer/article/details/126423676</a></p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">拉取镜像</span></span><br><span class="line">docker pull jenkins/jenkins</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">方便本地查看容器文件：将jenkins的工作目录，挂载到本地的目录（/home/jenkins_home）</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果需要部署多个jenkins实例，就把5000端口映射出去使用</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker run -u root -it --name jenkins --restart=always -p 8080:8080 -p 50000:50000 -v /home/jenkins_home:/var/jenkins_home -d jenkins/jenkins</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果单机部署jenkins就不用映射5000端口，先配置好maven本地仓库，不会每次都会重新下载依赖！！！！</span></span><br><span class="line">docker run -u root \</span><br><span class="line">	-it \</span><br><span class="line">	--name jenkins \</span><br><span class="line">	--restart=always \</span><br><span class="line">	-p 9999:8080 \</span><br><span class="line">	-v /home/jenkins_home:/var/jenkins_home \</span><br><span class="line">	-v /usr/local/maven:/usr/local/maven \</span><br><span class="line">	-v /usr/local/maven/repository:/usr/local/maven/repository \</span><br><span class="line">	-d jenkins/jenkins</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">设置正在运行的容器自启</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker update --restart=always 容器名称</span></span><br></pre></td></tr></table></figure>
<p>如果是直接使用java -jar 方式启动：</p>
<p>首次启动war包会在<code>/root/.jenkins</code>生成配置文件</p>
<p>待完全启动成功后 访问服务器8080端口完成配置</p>
<p>初始化后的密码：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Jenkins initial setup is required. An admin user has been created and a password generated.</span><br><span class="line">Please use the following password to proceed to installation:</span><br><span class="line">4e67bbe261da476abdc63c5b51311646</span><br><span class="line">This may also be found at: /root/.jenkins/secrets/initialAdminPassword</span><br></pre></td></tr></table></figure>
<p>密码文件使用后会自动删除</p>
<blockquote>
<p>获取默认登录密码</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">cat</span> /var/jenkins_home/secrets/initialAdminPassword</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果设置了数据卷</span></span><br><span class="line">cat /home/jenkins_home/secrets/initialAdminPassword</span><br></pre></td></tr></table></figure>
<h2 id="5-git安装"><a href="#5-git安装" class="headerlink" title="5.git安装"></a>5.git安装</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y git</span><br></pre></td></tr></table></figure>
<h2 id="6-Jenkins-Git-Maven-自动化部署配置"><a href="#6-Jenkins-Git-Maven-自动化部署配置" class="headerlink" title="6.Jenkins + Git + Maven 自动化部署配置"></a>6.Jenkins + Git + Maven 自动化部署配置</h2><h3 id="1-Git配置"><a href="#1-Git配置" class="headerlink" title="1 Git配置"></a>1 Git配置</h3><p><img src= "" data-lazy-src="image-20220726213303821.png" alt="image-20220726213303821"></p>
<p><img src= "" data-lazy-src="image-20220726213505879.png" alt="image-20220726213505879"></p>
<h3 id="2-Maven配置"><a href="#2-Maven配置" class="headerlink" title="2 Maven配置"></a>2 Maven配置</h3><blockquote>
<p>安装maven插件 Maven Integration</p>
</blockquote>
<p><img src= "" data-lazy-src="image-20220726214239888.png" alt="image-20220726214239888"></p>
<h3 id="3-Pom-xml配置"><a href="#3-Pom-xml配置" class="headerlink" title="3 Pom.xml配置"></a>3 Pom.xml配置</h3><p><img src= "" data-lazy-src="image-20220726214200732.png" alt="image-20220726214200732"></p>
<h3 id="4-publish-over-ssh-配置"><a href="#4-publish-over-ssh-配置" class="headerlink" title="4.publish over ssh 配置"></a>4.publish over ssh 配置</h3><p>1 安装插件</p>
<p>在Configure System菜单里 往下来</p>
<p>2 添加一台目标服务器</p>
<p><img src= "" data-lazy-src="image-20220726223917263.png" alt="image-20220726223917263"></p>
<p><img src= "" data-lazy-src="image-20220726223937722.png" alt="image-20220726223937722"></p>
<p>3 修改配置</p>
<p><img src= "" data-lazy-src="image-20220727165700419.png" alt="image-20220727165700419"></p>
<h4 id="4-1超时机制"><a href="#4-1超时机制" class="headerlink" title="4.1超时机制"></a>4.1超时机制</h4><p>输出命令时一定要注意不要让窗口卡主，不然Jenkins会认为认为一直没完成</p>
<h4 id="4-2shell的日志输出"><a href="#4-2shell的日志输出" class="headerlink" title="4.2shell的日志输出"></a>4.2shell的日志输出</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nohup java -jar /root/xxoo/demo*.jar &gt;mylog.log 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>
<h4 id="4-3数据流重定向"><a href="#4-3数据流重定向" class="headerlink" title="4.3数据流重定向"></a>4.3数据流重定向</h4><p>数据流重定向就是将某个命令执行后应该要出现在屏幕上的数据传输到其他地方</p>
<p>标准输入（stdin）：代码为0，使用&lt;或&lt;&lt;;<br>标准输出（stdout）：代码为1，使用&gt;或&gt;&gt;;<br>标准错误输出（stderr）：代码为2，使用2&gt;或2&gt;&gt;</p>
<p>> 覆盖写<br>>&gt; 追加写</p>
<h3 id="运行前清理"><a href="#运行前清理" class="headerlink" title="运行前清理"></a>运行前清理</h3><p>配置杀死之前运行的进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/bash</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">删除历史数据</span></span><br><span class="line">rm -rf xxoo</span><br><span class="line"></span><br><span class="line">appname=$1</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">获取传入的参数</span></span><br><span class="line">echo &quot;arg:$1&quot;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">获取正在运行的jar包pid</span></span><br><span class="line">pid=`ps -ef | grep $1 | grep &#x27;java -jar&#x27; | awk &#x27;&#123;printf $2&#125;&#x27;`</span><br><span class="line"></span><br><span class="line">echo $pid</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果pid为空，提示一下，否则，执行<span class="built_in">kill</span>命令</span></span><br><span class="line">if [ -z $pid ];</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">使用-z 做空值判断</span></span><br><span class="line">        then</span><br><span class="line">                echo &quot;$appname not started&quot;</span><br><span class="line"></span><br><span class="line">        else</span><br><span class="line">               kill -9 $pid</span><br><span class="line">                echo &quot;$appname stoping....&quot;</span><br><span class="line"></span><br><span class="line">	check=`ps -ef | grep -w $pid | grep java`</span><br><span class="line">    if [ -z $check ];</span><br><span class="line"></span><br><span class="line">            then</span><br><span class="line">                    echo &quot;$appname pid:$pid is stop&quot;</span><br><span class="line">            else</span><br><span class="line">                    echo &quot;$appname stop failed&quot;</span><br><span class="line">    fi</span><br><span class="line">fi</span><br></pre></td></tr></table></figure>
<h3 id="几种构建方式"><a href="#几种构建方式" class="headerlink" title="几种构建方式"></a>几种构建方式</h3><ul>
<li>快照依赖构建/Build whenever a SNAPSHOT dependency is built<ul>
<li>当依赖的快照被构建时执行本job</li>
</ul>
</li>
<li>触发远程构建 (例如,使用脚本)<ul>
<li>远程调用本job的restapi时执行本job</li>
</ul>
</li>
<li>job依赖构建/Build after other projects are built<ul>
<li>当依赖的job被构建时执行本job</li>
</ul>
</li>
<li>定时构建/Build periodically<ul>
<li>使用cron表达式定时构建本job</li>
</ul>
</li>
<li>向GitHub提交代码时触发Jenkins自动构建/GitHub hook trigger for GITScm polling<ul>
<li>Github-WebHook出发时构建本job</li>
</ul>
</li>
<li>定期检查代码变更/Poll SCM<ul>
<li>使用cron表达式定时检查代码变更，变更后构建本job</li>
</ul>
</li>
</ul>
<h4 id="触发远程构建-gitlab上改动自动构建"><a href="#触发远程构建-gitlab上改动自动构建" class="headerlink" title="触发远程构建/gitlab上改动自动构建"></a>触发远程构建/gitlab上改动自动构建</h4><p>代码改动自动可以使用gitlab的webhook回调钩子调起Jenkins的启动任务接口</p>
<p>在构建触发器中配置接口和token</p>
<p><img src= "" data-lazy-src="image-20220728170250273.png" alt="image-20220728170250273"></p>
<h4 id="定时构建"><a href="#定时构建" class="headerlink" title="定时构建"></a>定时构建</h4><h5 id="Jenkins-cron表达式"><a href="#Jenkins-cron表达式" class="headerlink" title="Jenkins cron表达式"></a>Jenkins cron表达式</h5><p>标准cron</p>
<p><a target="_blank" rel="noopener" href="https://crontab.guru">https://crontab.guru</a></p>
<p>Jenkins cron不是标准的cron表达式</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">第一个 * 表示每个小时的第几分钟，取值0~59</span><br><span class="line"></span><br><span class="line">H * * * *</span><br><span class="line">H：每小时执行一次</span><br><span class="line"></span><br><span class="line">第二颗 * 表示小时，取值0~23</span><br><span class="line"></span><br><span class="line">* 15 * * * 表示每天下午3点</span><br><span class="line">* 1 * * *  表示每天凌晨1点</span><br><span class="line"></span><br><span class="line">第三颗 * 表示一个月的第几天，取值1~31</span><br><span class="line">* 1 5 * *  表示每月5日凌晨1点</span><br><span class="line"></span><br><span class="line">第四颗 * 表示第几月，取值1~12</span><br><span class="line">* 15 5 1 *  表示每年几月执行</span><br><span class="line"></span><br><span class="line">第五颗 * 表示一周中的第几天，取值0~7，其中0和7代表的都是周日</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><strong>“/”</strong></p>
<p>表示每隔多长时间，比如 <em>/10 </em> <em> </em> * 表示 每隔10分钟</p>
<p><strong>“H”</strong></p>
<p>hash散列值，以job名取值，获取到以job名为入参的唯一值，相同名称值也相同，这个偏移量会和实际时间相加，获得一个真实的运行时间</p>
<p>意义在于：不同的项目在不同的时间运行，即使配置的值是一样的，比如 都是<code>15 * * * *</code> ，表示每个小时的第15分钟开始执行任务，那么会造成同一时间内在Jenkins中启动很多job，换成<code>H/15 * * * *</code>,那么在首次启动任务时，会有随机值参与进来，有的会在17分钟启动 有的会在19分钟启动，随后的启动时间也是这个值。这样就能错开相同cron值的任务执行了。</p>
<p>H的值也可以设置范围</p>
<p><code>H * * * *</code>表示一小时内的任意时间</p>
<p><code>*/10 * * * *</code>每10分钟</p>
<p><code>H/10 * * * *</code>每10分钟,可能是7,17,27，起始时间hash，步长不变</p>
<p><code>45 3 * * 1-6</code> 每个周一至周六，凌晨3点45 执行1次</p>
<p><code>45 3-5 * * 1-6</code> 每个周一至周六，凌晨3点45 ，凌晨4点45，凌晨5点45 各执行1次</p>
<p><code>H(40-48) 3-5 * * 1-6</code> 在40~48之间取值 其他同上</p>
<p><code>45 3-5/2 * * 1-6</code> 每个周一至周六，凌晨3点45 ，凌晨5点45 各执行1次</p>
<p><code>45 0-6/2 * * 1-6 * * 1-6</code> 0点开始，每间隔2小时执行一次 0:45、2:45、4:45</p>
<h4 id="源码变更构建"><a href="#源码变更构建" class="headerlink" title="源码变更构建"></a>源码变更构建</h4><p>使用Poll SCM 方式与Build periodically一样</p>
<p>会主动定期检查代码托管服务器上是否有变化，一旦发生变化执行job构建</p>
<h3 id="测试报告邮件通知"><a href="#测试报告邮件通知" class="headerlink" title="测试报告邮件通知"></a>测试报告邮件通知</h3><p>使用163免费邮箱发送邮件时注意密码填认证码，也就是发送手机短信后给的那个，不要用登录邮箱的密码</p>
<p>类似下面。。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">KDWJUWDQBWMOYGDC</span><br></pre></td></tr></table></figure>
<h3 id=""><a href="#" class="headerlink" title=" "></a> </h3><h3 id="自动化部署到docker容器中"><a href="#自动化部署到docker容器中" class="headerlink" title="自动化部署到docker容器中"></a>自动化部署到docker容器中</h3><h4 id="docker外挂目录"><a href="#docker外挂目录" class="headerlink" title="docker外挂目录"></a>docker外挂目录</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8080:8080 --name demo-out -v /root/jarfile/demo-1-0.0.1-SNAPSHOT.jar:/app.jar openjdk:11 java -jar app.jar</span><br></pre></td></tr></table></figure>
<h4 id="打包到容器内"><a href="#打包到容器内" class="headerlink" title="打包到容器内"></a>打包到容器内</h4><ol>
<li>准备一台测试服务器 docker环境</li>
<li>准备支持jdk的镜像</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">FROM openjdk:11</span><br><span class="line">COPY . /usr/src/myapp</span><br><span class="line">WORKDIR /usr/src/myapp</span><br><span class="line">RUN javac Main.java</span><br><span class="line">CMD [&quot;java&quot;, &quot;Main&quot;]</span><br></pre></td></tr></table></figure>
<ol>
<li>把jar包打包到容器内</li>
</ol>
<p>dockerfile</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> openjdk:<span class="number">11</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">8080</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">WORKDIR</span><span class="language-bash"> /root</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> jarfile/demo*.jar /root/app.jar</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="language-bash"> [<span class="string">&quot;java&quot;</span>,<span class="string">&quot;-jar&quot;</span>,<span class="string">&quot;/root/app.jar&quot;</span>]</span></span><br></pre></td></tr></table></figure>
<p>打包镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build -t demo .</span><br></pre></td></tr></table></figure>
<p>执行远程脚本</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name demo-test -p8080:8080 -d demo</span><br></pre></td></tr></table></figure>
<p>配置国内镜像</p>
<p>修改<code>/etc/docker/daemon.json</code>文件，没有的话创建一个</p>
<p>写入</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [</span><br><span class="line">        &quot;https://ustc-edu-cn.mirror.aliyuncs.com&quot;,</span><br><span class="line">        &quot;http://hub-mirror.c.163.com&quot;,</span><br><span class="line">        &quot;https://registry.aliyuncs.com&quot;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>重启服务</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure>
<h2 id="7-Jenkins集群-并发构建"><a href="#7-Jenkins集群-并发构建" class="headerlink" title="7.Jenkins集群/并发构建"></a>7.Jenkins集群/并发构建</h2><p>集群化构建可以有效提升构建效率，尤其是团队项目比较多或是子项目比较多的时候，可以并发在多台机器上执行构建。</p>
<h2 id="8-流水线-pipeline"><a href="#8-流水线-pipeline" class="headerlink" title="8.流水线 pipeline"></a>8.流水线 pipeline</h2><p>流水线既能作为任务的本身，也能作为Jenkinsfile</p>
<p>使用流水线可以让我们的任务从ui手动操作，转换为代码化，像docker的dockerfile一样，从shell命令到配置文件，更适合大型项目，可以让团队其他开发者同时参与进来，同时也可以编辑开发Jenkinswebui不能完成的更复杂的构建逻辑，作为开发者可读性也更好。</p>
<h3 id="完整语法"><a href="#完整语法" class="headerlink" title="完整语法"></a>完整语法</h3><p>5个必备的组成部分</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">pipeline：整条流水线</span><br><span class="line">agent：指定执行器</span><br><span class="line">stages：所有阶段</span><br><span class="line">stage：某一阶段，可有多个</span><br><span class="line">steps：阶段内的每一步，可执行命令</span><br></pre></td></tr></table></figure>
<h3 id="测试脚本"><a href="#测试脚本" class="headerlink" title="测试脚本"></a>测试脚本</h3><h4 id="基础框架"><a href="#基础框架" class="headerlink" title="基础框架"></a>基础框架</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">pipeline &#123;</span><br><span class="line">    agent any</span><br><span class="line"></span><br><span class="line">    stages &#123;</span><br><span class="line">        stage(&#x27;拉取代码&#x27;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">            </span><br><span class="line">                echo &#x27;拉取代码完成&#x27;</span><br><span class="line">               </span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        stage(&#x27;执行构建&#x27;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                echo &#x27;执行构建完成&#x27;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    post &#123;</span><br><span class="line">        </span><br><span class="line">        always &#123;</span><br><span class="line">            </span><br><span class="line">            echo &quot;完成&quot;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        failure &#123;</span><br><span class="line">            </span><br><span class="line">            echo &quot;失败&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="阶段视图-Stage-View"><a href="#阶段视图-Stage-View" class="headerlink" title="阶段视图 Stage View"></a>阶段视图 Stage View</h4><h4 id="blue-ocean可视化界面"><a href="#blue-ocean可视化界面" class="headerlink" title="blue ocean可视化界面"></a>blue ocean可视化界面</h4><p>全新的流水线控制ui，可重复执行某阶段代码</p>
<p>插件中心搜索blue ocean安装即可</p>
<h4 id="post"><a href="#post" class="headerlink" title="post"></a>post</h4><p>流水线完成后可执行的任务</p>
<ul>
<li>always 无论流水线或者阶段的完成状态。</li>
<li>changed 只有当流水线或者阶段完成状态与之前不同时。</li>
<li>failure 只有当流水线或者阶段状态为”failure”运行。</li>
<li>success 只有当流水线或者阶段状态为”success”运行。</li>
<li>unstable 只有当流水线或者阶段状态为”unstable”运行。例如：测试失败。</li>
<li>aborted 只有当流水线或者阶段状态为”aborted “运行。例如：手动取消。</li>
</ul>
<h4 id="agent"><a href="#agent" class="headerlink" title="agent"></a>agent</h4><p>可以指定执行节点</p>
<p>label 指定运行job的节点标签</p>
<p>any 不指定，由Jenkins分配</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">pipeline &#123;</span><br><span class="line">    agent &#123;</span><br><span class="line">        node &#123;</span><br><span class="line">            label &quot;jenkins-02&quot;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    stages &#123;</span><br><span class="line">        stage(&#x27;拉取代码&#x27;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">          </span><br><span class="line">                sh &quot;&quot;&quot;</span><br><span class="line">                    sleep 10</span><br><span class="line">                            </span><br><span class="line">                   &quot;&quot;&quot;</span><br><span class="line"></span><br><span class="line">                echo &#x27;拉取代码完成&#x27;</span><br><span class="line">               </span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        stage(&#x27;执行构建&#x27;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                echo &#x27;执行构建完成&#x27;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    post &#123;</span><br><span class="line">        </span><br><span class="line">        always &#123;</span><br><span class="line">            </span><br><span class="line">            echo &quot;完成&quot;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        failure &#123;</span><br><span class="line">            </span><br><span class="line">            echo &quot;失败&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="pipeline中执行自动化构建"><a href="#pipeline中执行自动化构建" class="headerlink" title="pipeline中执行自动化构建"></a>pipeline中执行自动化构建</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">pipeline &#123;</span><br><span class="line">    agent any</span><br><span class="line"></span><br><span class="line">    tools &#123;</span><br><span class="line">        </span><br><span class="line">        maven &quot;maven3&quot;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    stages &#123;</span><br><span class="line">        stage(&quot;拉取代码&quot;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                </span><br><span class="line">                </span><br><span class="line">                git branch: &#x27;main&#x27;, credentialsId: &#x27;gitlab&#x27;, url: &#x27;http://192.168.44.103/root/java-project.git&#x27;</span><br><span class="line">                echo &#x27;拉取成功&#x27;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        stage(&quot;执行构建&quot;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                </span><br><span class="line">            //    sh &quot;mvn --version&quot;</span><br><span class="line">                sh &quot;&quot;&quot; </span><br><span class="line">                cd demo-1</span><br><span class="line">                </span><br><span class="line">                mvn clean package</span><br><span class="line">                &quot;&quot;&quot;</span><br><span class="line">                </span><br><span class="line">                echo &#x27;构建完成&#x27;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        stage(&quot;clean test server&quot;)&#123;</span><br><span class="line">            </span><br><span class="line">            steps&#123;</span><br><span class="line">                </span><br><span class="line">sshPublisher(publishers: [sshPublisherDesc(configName: &#x27;testserver&#x27;, transfers: [sshTransfer(cleanRemote: false, excludes: &#x27;&#x27;, execCommand: &#x27;&#x27;&#x27;rm -rf *</span><br><span class="line"></span><br><span class="line">docker stop demo</span><br><span class="line">docker rm demo</span><br><span class="line">docker rmi demo</span><br><span class="line">&#x27;&#x27;&#x27;, execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: &#x27;[, ]+&#x27;, remoteDirectory: &#x27;&#x27;, remoteDirectorySDF: false, removePrefix: &#x27;&#x27;, sourceFiles: &#x27;/root&#x27;)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        stage(&quot;发送jar包到测试服务器&quot;) &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                </span><br><span class="line">                sshPublisher(publishers: [sshPublisherDesc(configName: &#x27;testserver&#x27;, transfers: [sshTransfer(cleanRemote: false, excludes: &#x27;&#x27;, execCommand: &#x27;&#x27;, execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: &#x27;[, ]+&#x27;, remoteDirectory: &#x27;/jarfile&#x27;, remoteDirectorySDF: false, removePrefix: &#x27;demo-1/target&#x27;, sourceFiles: &#x27;**/demo*.jar&#x27;), sshTransfer(cleanRemote: false, excludes: &#x27;&#x27;, execCommand: &#x27;&#x27;&#x27;docker build -t demo .</span><br><span class="line">docker run -d -p 8080:8080 --name demo demo&#x27;&#x27;&#x27;, execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: &#x27;[, ]+&#x27;, remoteDirectory: &#x27;/&#x27;, remoteDirectorySDF: false, removePrefix: &#x27;demo-1/docker&#x27;, sourceFiles: &#x27;demo-1/docker/dockerfile&#x27;)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])</span><br><span class="line">                </span><br><span class="line">                </span><br><span class="line">                echo &#x27;jar send over!&#x27;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="声明式流水线"><a href="#声明式流水线" class="headerlink" title="声明式流水线"></a>声明式流水线</h4><p>好处</p>
<ul>
<li>更像是在Jenkins web ui中的操作</li>
<li>可读性比较高</li>
<li>可以使用blue ocean自动生成</li>
<li>支持语法检查</li>
</ul>
<p>坏处</p>
<ul>
<li>代码逻辑能力比脚本式弱，不能完成特别复杂的任务    </li>
</ul>
<h4 id="脚本式流水线"><a href="#脚本式流水线" class="headerlink" title="脚本式流水线"></a>脚本式流水线</h4><p>好处</p>
<ul>
<li>更少的代码和弱规范要求</li>
<li>更灵活的自定义代码操作</li>
<li>不受约束，可以构建特别复杂的工作流和流水线</li>
</ul>
<p>坏处</p>
<ul>
<li>读写对编程要求比较高</li>
<li>比声明式流水线代码更复杂</li>
</ul>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/jenkins/">jenkins</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/nginx/Nginx%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/"><img class="prev-cover" src= "" data-lazy-src="/images/nginx.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Nginx安装配置</div></div></a></div><div class="next-post pull-right"><a href="/blog/utils/base64%E3%80%81url%E3%80%81blob%E4%BA%92%E7%9B%B8%E8%BD%AC%E6%8D%A2/"><img class="next-cover" src= "" data-lazy-src="/images/tran.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">base64、url、blob互相转换</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/jenkins/部署spring项目/" title="Jenkins 部署spring项目"><img class="cover" src= "" data-lazy-src="/images/spring.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-03-18</div><div class="title">Jenkins 部署spring项目</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">一切解释权归本咸鱼所有</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-GitLab%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">1.GitLab安装使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%9C%A8ssh%E4%B8%8B%E5%AE%89%E8%A3%85"><span class="toc-number">1.1.</span> <span class="toc-text">1.在ssh下安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96"><span class="toc-number">1.1.1.</span> <span class="toc-text">1 安装依赖</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E9%85%8D%E7%BD%AE%E9%95%9C%E5%83%8F"><span class="toc-number">1.1.2.</span> <span class="toc-text">2 配置镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%BC%80%E5%A7%8B%E5%AE%89%E8%A3%85"><span class="toc-number">1.1.3.</span> <span class="toc-text">3 开始安装</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-gitlab%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">1.1.4.</span> <span class="toc-text">4 gitlab常用命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E8%87%AA%E5%90%AF%E8%AE%BE%E7%BD%AE"><span class="toc-number">1.1.5.</span> <span class="toc-text">5 自启设置</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%9C%A8docker%E4%B8%8B%E5%AE%89%E8%A3%85"><span class="toc-number">1.2.</span> <span class="toc-text">2.在docker下安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E6%8B%89%E5%8F%96%E9%95%9C%E5%83%8F"><span class="toc-number">1.2.1.</span> <span class="toc-text">1 拉取镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%B7%BB%E5%8A%A0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">1.2.2.</span> <span class="toc-text">2 添加环境变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%B7%BB%E5%8A%A0%E5%AE%B9%E5%99%A8"><span class="toc-number">1.2.3.</span> <span class="toc-text">2 添加容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8"><span class="toc-number">1.2.4.</span> <span class="toc-text">2.启动容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E6%9F%A5%E7%9C%8B%E5%B7%B2%E5%AD%98%E5%9C%A8%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">1.2.5.</span> <span class="toc-text">3.查看已存在的容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E8%BF%9B%E5%85%A5%E5%AE%B9%E5%99%A8"><span class="toc-number">1.2.6.</span> <span class="toc-text">4.进入容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E8%AE%BF%E9%97%AE"><span class="toc-number">1.2.7.</span> <span class="toc-text">3.访问</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E7%AE%A1%E7%90%86%E5%91%98%E8%B4%A6%E5%8F%B7%E7%99%BB%E5%BD%95"><span class="toc-number">1.2.8.</span> <span class="toc-text">4.管理员账号登录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E5%85%B6%E4%BB%96%E9%85%8D%E7%BD%AE"><span class="toc-number">1.2.9.</span> <span class="toc-text">5.其他配置</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%AE%89%E8%A3%85JDK"><span class="toc-number">2.</span> <span class="toc-text">2.安装JDK</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%A3%80%E7%B4%A2%E5%8F%AF%E7%94%A8%E5%8C%85"><span class="toc-number">2.1.</span> <span class="toc-text">1 检索可用包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E9%85%8D%E7%BD%AEJAVA-HOME"><span class="toc-number">2.2.</span> <span class="toc-text">2.配置JAVA_HOME</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-Maven%E5%AE%89%E8%A3%85"><span class="toc-number">3.</span> <span class="toc-text">3.Maven安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-%E9%85%8D%E7%BD%AEMAVEN-HOME"><span class="toc-number">3.1.</span> <span class="toc-text">3.1 配置MAVEN_HOME</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2Maven%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F"><span class="toc-number">3.2.</span> <span class="toc-text">3.2Maven阿里云镜像</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%AE%89%E8%A3%85Jenkins"><span class="toc-number">4.</span> <span class="toc-text">4.安装Jenkins</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-git%E5%AE%89%E8%A3%85"><span class="toc-number">5.</span> <span class="toc-text">5.git安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-Jenkins-Git-Maven-%E8%87%AA%E5%8A%A8%E5%8C%96%E9%83%A8%E7%BD%B2%E9%85%8D%E7%BD%AE"><span class="toc-number">6.</span> <span class="toc-text">6.Jenkins + Git + Maven 自动化部署配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-Git%E9%85%8D%E7%BD%AE"><span class="toc-number">6.1.</span> <span class="toc-text">1 Git配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-Maven%E9%85%8D%E7%BD%AE"><span class="toc-number">6.2.</span> <span class="toc-text">2 Maven配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-Pom-xml%E9%85%8D%E7%BD%AE"><span class="toc-number">6.3.</span> <span class="toc-text">3 Pom.xml配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-publish-over-ssh-%E9%85%8D%E7%BD%AE"><span class="toc-number">6.4.</span> <span class="toc-text">4.publish over ssh 配置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#4-1%E8%B6%85%E6%97%B6%E6%9C%BA%E5%88%B6"><span class="toc-number">6.4.1.</span> <span class="toc-text">4.1超时机制</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-2shell%E7%9A%84%E6%97%A5%E5%BF%97%E8%BE%93%E5%87%BA"><span class="toc-number">6.4.2.</span> <span class="toc-text">4.2shell的日志输出</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-3%E6%95%B0%E6%8D%AE%E6%B5%81%E9%87%8D%E5%AE%9A%E5%90%91"><span class="toc-number">6.4.3.</span> <span class="toc-text">4.3数据流重定向</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E5%89%8D%E6%B8%85%E7%90%86"><span class="toc-number">6.5.</span> <span class="toc-text">运行前清理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%87%A0%E7%A7%8D%E6%9E%84%E5%BB%BA%E6%96%B9%E5%BC%8F"><span class="toc-number">6.6.</span> <span class="toc-text">几种构建方式</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A6%E5%8F%91%E8%BF%9C%E7%A8%8B%E6%9E%84%E5%BB%BA-gitlab%E4%B8%8A%E6%94%B9%E5%8A%A8%E8%87%AA%E5%8A%A8%E6%9E%84%E5%BB%BA"><span class="toc-number">6.6.1.</span> <span class="toc-text">触发远程构建&#x2F;gitlab上改动自动构建</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E6%9E%84%E5%BB%BA"><span class="toc-number">6.6.2.</span> <span class="toc-text">定时构建</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Jenkins-cron%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">6.6.2.1.</span> <span class="toc-text">Jenkins cron表达式</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%BA%90%E7%A0%81%E5%8F%98%E6%9B%B4%E6%9E%84%E5%BB%BA"><span class="toc-number">6.6.3.</span> <span class="toc-text">源码变更构建</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E6%8A%A5%E5%91%8A%E9%82%AE%E4%BB%B6%E9%80%9A%E7%9F%A5"><span class="toc-number">6.7.</span> <span class="toc-text">测试报告邮件通知</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">6.8.</span> <span class="toc-text"> </span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E5%8C%96%E9%83%A8%E7%BD%B2%E5%88%B0docker%E5%AE%B9%E5%99%A8%E4%B8%AD"><span class="toc-number">6.9.</span> <span class="toc-text">自动化部署到docker容器中</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#docker%E5%A4%96%E6%8C%82%E7%9B%AE%E5%BD%95"><span class="toc-number">6.9.1.</span> <span class="toc-text">docker外挂目录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%89%93%E5%8C%85%E5%88%B0%E5%AE%B9%E5%99%A8%E5%86%85"><span class="toc-number">6.9.2.</span> <span class="toc-text">打包到容器内</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-Jenkins%E9%9B%86%E7%BE%A4-%E5%B9%B6%E5%8F%91%E6%9E%84%E5%BB%BA"><span class="toc-number">7.</span> <span class="toc-text">7.Jenkins集群&#x2F;并发构建</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E6%B5%81%E6%B0%B4%E7%BA%BF-pipeline"><span class="toc-number">8.</span> <span class="toc-text">8.流水线 pipeline</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%8C%E6%95%B4%E8%AF%AD%E6%B3%95"><span class="toc-number">8.1.</span> <span class="toc-text">完整语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC"><span class="toc-number">8.2.</span> <span class="toc-text">测试脚本</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9F%BA%E7%A1%80%E6%A1%86%E6%9E%B6"><span class="toc-number">8.2.1.</span> <span class="toc-text">基础框架</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%98%B6%E6%AE%B5%E8%A7%86%E5%9B%BE-Stage-View"><span class="toc-number">8.2.2.</span> <span class="toc-text">阶段视图 Stage View</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#blue-ocean%E5%8F%AF%E8%A7%86%E5%8C%96%E7%95%8C%E9%9D%A2"><span class="toc-number">8.2.3.</span> <span class="toc-text">blue ocean可视化界面</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#post"><span class="toc-number">8.2.4.</span> <span class="toc-text">post</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#agent"><span class="toc-number">8.2.5.</span> <span class="toc-text">agent</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#pipeline%E4%B8%AD%E6%89%A7%E8%A1%8C%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA"><span class="toc-number">8.3.</span> <span class="toc-text">pipeline中执行自动化构建</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A3%B0%E6%98%8E%E5%BC%8F%E6%B5%81%E6%B0%B4%E7%BA%BF"><span class="toc-number">8.3.1.</span> <span class="toc-text">声明式流水线</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%84%9A%E6%9C%AC%E5%BC%8F%E6%B5%81%E6%B0%B4%E7%BA%BF"><span class="toc-number">8.3.2.</span> <span class="toc-text">脚本式流水线</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring Security &amp; Oauth2"/></a><div class="content"><a class="title" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2">Spring Security &amp; Oauth2</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类"><img src= "" data-lazy-src="/images/jwt.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JWT工具类"/></a><div class="content"><a class="title" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类">JWT工具类</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringSecurity 集成示例"/></a><div class="content"><a class="title" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例">SpringSecurity 集成示例</a><time datetime="2024-04-25T07:24:43.000Z" title="发表于 2024-04-25 15:24:43">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成"><img src= "" data-lazy-src="/images/mybatis-plus.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MybatisPlus 快速集成"/></a><div class="content"><a class="title" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成">MybatisPlus 快速集成</a><time datetime="2024-04-21T07:39:43.000Z" title="发表于 2024-04-21 15:39:43">2024-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成"><img src= "" data-lazy-src="/images/mybaits.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Mybatis 快速集成"/></a><div class="content"><a class="title" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成">Mybatis 快速集成</a><time datetime="2024-04-21T07:24:43.000Z" title="发表于 2024-04-21 15:24:43">2024-04-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By mowei</div><div class="footer_custom_text">海内存知已，天涯若比邻</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      true && mermaid.init()
    })
  }
}</script></div><div class="aplayer no-destroy" data-id="9385310356" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.removeEventListener('scroll', window.tocScrollFn)
  window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2d_models/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2d_models/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2d_models/assets/wanko.model.json"},"display":{"position":"left","width":100,"height":150,"hOffset":-10,"vOffset":40},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body></html>